<template>
  <div class="svg-icon" :style="{ width: size + 'px', height: size + 'px' }" style="background: transparent; display: block;">
    <svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg">
      <g v-html="parsedPath"></g>
    </svg>
  </div>
</template>

<script setup>
import { computed } from 'vue'

const props = defineProps({
  path: {
    type: String,
    required: true
  },
  color: {
    type: String,
    default: 'currentColor'
  },
  size: {
    type: [String, Number],
    default: 24
  }
})

// 替换所有 fill 值为当前颜色
const parsedPath = computed(() => {
  return props.path
    .replace(/fill="[^"]*"/g, `fill="${props.color}"`);
});
</script>

<style scoped>
.svg-icon svg {
  background: transparent;
  width: 100%;
  height: 100%;
}
</style>